<template>
  <div>
    <el-dialog
        :visible.sync="dialogVisible"
        width="800px"
        :before-close="handleClose">
      <el-form ref="form" v-if="isReg" :model="form" label-width="80px">
        <div class="logo">
          <img src="@/assets/image/logo.png" alt="">
        </div>
        <el-form-item label="头像">
          <el-upload
              class="avatar-uploader"
              action="https://jsonplaceholder.typicode.com/posts/"
              :show-file-list="false"
              :on-success="handleAvatarSuccess"
              :before-upload="beforeAvatarUpload">
            <img v-if="imageUrl" :src="imageUrl" class="avatars">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="您的姓名">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="联系电话">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="选择性别">
          <el-radio-group v-model="form.resource">
            <el-radio label="男"></el-radio>
            <el-radio label="女"></el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="出生时间">
          <el-date-picker type="date" placeholder="选择日期" v-model="form.date1" style="width: 100%;"></el-date-picker>
        </el-form-item>
        <el-form-item label="居住地址">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="婚姻状况">
          <el-radio-group v-model="form.resource">
            <el-radio label="离婚"></el-radio>
            <el-radio label="未婚"></el-radio>
            <el-radio label="丧偶"></el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="兴趣爱好">
          <el-input type="textarea" :rows="5" v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item>
          <div class="box-1">
            <a href="javascript:void (0)">立即注册</a>
            <a href="javascript:void (0)" @click="isReg=false" class="reg">立即登录</a>
          </div>
        </el-form-item>
      </el-form>
      <div class="box-center"  v-else>
        <div class="left-box">
          <img src="@/assets/image/logo.webp" alt="">
        </div>
        <el-form class="right-1" ref="form" :model="form" label-width="0px">
          <div class="logo">
            <img src="@/assets/image/logo.png" alt="">
          </div>
          <el-form-item>
            <el-input v-model="form.name" placeholder="请输入用户名"></el-input>
          </el-form-item>
          <el-form-item>
            <el-input v-model="form.name" placeholder="请输入密码"></el-input>
          </el-form-item>
          <el-form-item>
            <div class="box-1">
              <a href="javascript:void (0)">立即登录</a>
              <a href="javascript:void (0)" @click="isReg=true" class="reg">立即注册</a>
            </div>

          </el-form-item>
        </el-form>
      </div>

    </el-dialog>
  </div>
</template>

<script>
export default {
  props:['isShow'],
  data(){
    return{
      dialogVisible:false,
      imageUrl: '',
      isReg:false,
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      }
    }
  },
  methods:{
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      // const isJPG = file.type === 'image/jpeg';
      // const isLt2M = file.size / 1024 / 1024 < 2;
      //
      // if (!isJPG) {
      //   this.$message.error('上传头像图片只能是 JPG 格式!');
      // }
      // if (!isLt2M) {
      //   this.$message.error('上传头像图片大小不能超过 2MB!');
      // }
      // return isJPG && isLt2M;
    },
    handleClose(){
      this.dialogVisible=false
    },
    onSubmit() {
      console.log('submit!');
    }
  },
  mounted() {
    if (this.isShow){
      this.dialogVisible = true
    }else{
      this.dialogVisible = false
    }
  },

  watch:{
    isShow(newValue,oldValue){
      if (this.isShow){
        this.dialogVisible = true
      }else{
        this.dialogVisible = false
      }
    }
  }
}
</script>

<style scoped lang="scss">
.logo{
  width: 100%;
  text-align: center;
  margin-bottom: 40px;
}
.box-1{
  width: 100%;
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
  a{
    display: flex;
    width: 48%;
    height: 45px;
    justify-content: center;
    align-items: center;
    font-size: 14px;
    color: #fff;
    background: #fc476d;
    border: 1px solid #fc476d;

  }
  .reg{
    background: transparent;
    border: 1px solid #999;
    color: #666666;
  }
}
::v-deep(.el-dialog){
  border-radius: 15px;
  padding: 0;

}
.avatar-uploader{
  width: 150px;
  height: 150px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  border: 1px dashed #d9d9d9;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 150px;
  height: 150px;
  line-height: 150px;
  text-align: center;
}
.avatars {
  width: 150px;
  height: 150px;
  display: block;
}

.box-center{
  width: 100%;
  display: flex;
  justify-content: space-between;
  .left-box{
    width: 380px;
    min-height: 450px;
    border-right: 1px solid #f7f7f7;
    img{
      width: 380px;
      height: 450px;
      object-fit: cover;
    }
  }
  .right-1{
    width: 350px;
  }
}

</style>
